/*
 * @(#)ContactPartyTransformer.java
 * Date 2013-08-15
 * Version 1.0
 * Author Jim Horner
 * Copyright (c)2012
 */


package us.hornerscorners.lamppost.pix.transformer;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.enterprise.context.ApplicationScoped;

import javax.inject.Inject;

import org.hl7.v3.COCTMT150003UV03ContactParty;
import org.hl7.v3.COCTMT150007UVContactParty;

import us.hornerscorners.lamppost.exception.ServiceActionException;

import us.hornerscorners.lamppost.model.patient.ContactParty;

import us.hornerscorners.lamppost.transformer.AbstractTransformer;


/**
 *
 * @author jim
 */
@ApplicationScoped
public class ContactPartyTransformer
        extends AbstractTransformer<COCTMT150003UV03ContactParty, ContactParty> {

    /** Field description */
    @Inject
    private InstanceIdentifierTransformer instanceIdentifierTransformer;

    /** Field description */
    @Inject
    private PersonNameTransformer personNameTransformer;

    /** Field description */
    @Inject
    private PhoneNumberTransformer phoneNumberTransformer;

    /** Field description */
    @Inject
    private PostalAddressTransformer postalAddressTransformer;

    /**
     * Constructs ...
     *
     */
    public ContactPartyTransformer() {
        super();
    }

    /**
     * Method description
     *
     *
     * @param prpaParty
     *
     * @return
     */
    @Override
    public ContactParty transform(COCTMT150003UV03ContactParty prpaParty)
            throws ServiceActionException {

        ContactParty result = null;

        if (prpaParty != null) {

            result = new ContactParty();

            result.getIdentifiers().addAll(
                this.instanceIdentifierTransformer.transform(prpaParty.getId()));

            result.getPersonNames().addAll(
                this.personNameTransformer.transformCOCTMT150003UV03Person(
                    prpaParty.getContactPerson()));

            result.getPhoneNumbers().addAll(
                this.phoneNumberTransformer.transform(prpaParty.getTelecom()));

            result.getPostalAddresses().addAll(
                this.postalAddressTransformer.transform(prpaParty.getAddr()));
        }

        return result;
    }

    /**
     * Method description
     *
     *
     * @param prpaParty
     *
     * @return
     */
    public ContactParty transform(COCTMT150007UVContactParty prpaParty)
            throws ServiceActionException {

        ContactParty result = null;

        if (prpaParty != null) {

            result = new ContactParty();

            result.getIdentifiers().addAll(
                this.instanceIdentifierTransformer.transform(prpaParty.getId()));

            result.getPersonNames().addAll(
                this.personNameTransformer.transformCOCTMT150007UVPerson(
                    prpaParty.getContactPerson()));

            result.getPhoneNumbers().addAll(
                this.phoneNumberTransformer.transform(prpaParty.getTelecom()));

            result.getPostalAddresses().addAll(
                this.postalAddressTransformer.transform(prpaParty.getAddr()));
        }

        return result;
    }

    /**
     * Method description
     *
     *
     * @param contacts
     *
     * @return
     */
    public Collection<ContactParty> transformCOCTMT150007UVContactParty(
            Collection<COCTMT150007UVContactParty> contacts) throws ServiceActionException {

        List<ContactParty> result = new ArrayList<>();

        for (COCTMT150007UVContactParty contact : contacts) {
            
            result.add(transform(contact));
        }

        return result;
    }
}
